local skill = fk.CreateSkill{
  name = "tea__liaoge",
}
---@type TrigSkelSpec<TrigFunc>
local liaoge = {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if event == fk.TurnStart then
      return player:hasSkill(skill.name) and not player:isNude() and target ~= player and #player:getPile("$liaoge_pile") == 0
    else
      return player:hasSkill(skill.name) and #player:getPile("$liaoge_pile") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnStart then
      local cid = player.room:askToCards(player, {
        min_num = 1,
        max_num = 1,
        skill_name = skill.name,
        include_equip = true,
        prompt = "#tea__liaoge-invoke",
      })
      if #cid > 0 then
        event:setCostData(self, cid)
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, skill.name, "special")
    if event == fk.TurnStart then
      local cid = event:getCostData(self)
      player:addToPile("$liaoge_pile", cid, false, skill.name, player.id)
    else
      local cids = player:getPile("$liaoge_pile")
      local c = Fk:getCardById(cids[1])
      local usedSalsh
      room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
        local use = e.data
        if use.card.trueName == "slash" then
          usedSalsh = true
        end
        return false
      end, Player.HistoryTurn)

      --语音
      if usedSalsh then
        if c.color == Card.Black then
          player:broadcastSkillInvoke(skill.name, 1)
        else
          player:broadcastSkillInvoke(skill.name, 3)
        end
      else
        if c.color == Card.Black then
          player:broadcastSkillInvoke(skill.name, 2)
        else
          player:broadcastSkillInvoke(skill.name, 4)
        end
      end

      if (usedSalsh and c.color == Card.Black) or (not usedSalsh and c.color == Card.Red) then
        room:obtainCard(player, cids, true, fk.ReasonJustMove)
        if not player.dead then
          player:drawCards(1, skill.name)
        end
      else
        room:throwCard(cids, skill.name, player)
      end
    end
  end,
}
skill:addEffect(fk.TurnStart, liaoge)
skill:addEffect(fk.TurnEnd, liaoge)
return skill